# select and copy certain files to send to a "dataverse" directory which will then be zipped for dataverse
library(fs)


to_path <- "~/Dropbox/das-evaluation_dataverse/" # change to local path

# README, data-raw, and gitignore
dir_create(path(to_path, "data-raw"))
fs::file_copy("README.md", path(to_path, "000_README.md"), overwrite = TRUE)
file_copy("data-raw/README.md", path(to_path, "data-raw"), overwrite = TRUE)
file_copy(".gitignore", to_path, overwrite = TRUE)



# Code -----
script_dirs <- dir_ls("R", recurse = TRUE, type = "directory")
dir_create(path(to_path, script_dirs))

script_files <- dir_ls("R", recurse = TRUE, type = "file") %>%
    str_subset("wru-NC", negate = TRUE) %>%  # remove some
    str_subset("z_helper", negate = TRUE)

# copy
for (subdir in unique(path_dir(script_files))) {
    file_copy(dir_ls(subdir, regexp = "\\.R", type = "file"),
              path(to_path, subdir),
              overwrite = TRUE)
}



# Data ----
data_dirs <- dir_ls("data", recurse = TRUE, type = "directory")
dir_create(path(to_path, data_dirs))

data_files <- dir_ls("data", recurse = TRUE, type = "file") %>%
    str_subset("sim", negate = TRUE) %>%  # remove sims
    str_subset("prepped_nc_block.Rds", negate = TRUE) %>%  # karge intermediated datasets
    str_subset("numbers/", negate = TRUE) %>%  # helper tex files
    str_subset("parity/", negate = TRUE) %>%  # helper tex files
    str_subset("wru-NC", negate = TRUE) # helper tex files

# copy
for (subdir in unique(path_dir(data_files))) {
    subdir_alldata <- dir_ls(subdir, type = "file")

    file_copy(subdir_alldata[which(subdir_alldata %in% data_files)],
              path(to_path, subdir),
              overwrite = TRUE)
}
